package com.sip.stream.utils.zfy.voice;

import android.content.Context;
import android.os.Build;
import android.os.VibrationEffect;
import android.os.Vibrator;

import com.sip.stream.ClientApp;

public class VibratorBeepPovider extends AbstractBeepProvider {
    private Vibrator vibrator;

    @Override
    public void playRedBlueAlarm(boolean z) {
    }

    @Override
    public void play(String str, String str2) {
        if (Build.VERSION.SDK_INT >= 26) {
            getVibrator().vibrate(VibrationEffect.createOneShot(500L, 1));
        } else {
            getVibrator().vibrate(500L);
        }
    }

    @Override
    public void release() {
        Vibrator vibrator = this.vibrator;
        if (vibrator != null) {
            vibrator.cancel();
            this.vibrator = null;
        }
    }

    @Override
    public void beepOneShot() {
        if (Build.VERSION.SDK_INT >= 26) {
            getVibrator().vibrate(VibrationEffect.createOneShot(500L, 1));
        } else {
            getVibrator().vibrate(500L);
        }
    }

    private Vibrator getVibrator() {
        if (this.vibrator == null) {
            this.vibrator = (Vibrator) ClientApp.clientApp.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
        }
        return this.vibrator;
    }
}
